Skip to content

[Platform] Add support for Google vertex AI #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

junaidbinfarooq
Copy link
Contributor

@junaidbinfarooq junaidbinfarooq commented Aug 10, 2025

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues #16 #272
License MIT

Changes proposed:

  • The PR aims to add support for Google's Vertex AI
  • Support is added for text generation, embeddings, server tools, etc
  • I created a separate directory inside the Bridge directory for the said bridge. Moving forward, we could either create a new namespace named Google and add two namespaces inside it, one each for Gemini and VertexAi, or we could simply keep VertexAi and remove the other, as this api already supports Gemini and more. Either way, Normalize Gemini vs Google #146 would be addressed.
  • I exempted the use of api key from the implementation so far as VertexAi supports two auth mechanisms, Api keys and ADC, ie, Application Default Credentials. The former is recommended for testing while the latter is recommended for production, IIRC. However, it does need to install gCloud on the server and locally too (if verifying the behavior without an api key). The Google auth library is also needed for automatic credential discovery.
  • More information can be found at https://cloud.google.com/vertex-ai/generative-ai/docs

@junaidbinfarooq junaidbinfarooq changed the title feat(platform): Add support for Google vertex AI [Platform] Add support for Google vertex AI Aug 11, 2025
@junaidbinfarooq junaidbinfarooq marked this pull request as ready for review August 11, 2025 14:37
@carsonbot carsonbot added Feature New feature Platform Issues & PRs about the AI Platform component Status: Needs Review labels Aug 11, 2025
@junaidbinfarooq junaidbinfarooq force-pushed the feat/platform-support-for-vertex-ai branch 2 times, most recently from 14ae923 to 35d9a8b Compare August 11, 2025 21:53
@@ -22,6 +22,7 @@
"require": {
"php": ">=8.2",
"ext-fileinfo": "*",
"google/auth": "^1.47",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move it to require-dev and add a check for the class existence to the implementation, like in the Bedrock one for example:

if (!class_exists(BedrockRuntimeClient::class)) {
throw new RuntimeException('For using the Bedrock platform, the async-aws/bedrock-runtime package is required. Try running "composer require async-aws/bedrock-runtime".');
}

@junaidbinfarooq junaidbinfarooq force-pushed the feat/platform-support-for-vertex-ai branch from 35d9a8b to 9124195 Compare August 12, 2025 07:52
?Contract $contract = null,
): Platform {
if (!class_exists(ApplicationDefaultCredentials::class)) {
throw new RuntimeException('For using the Bedrock platform, the google/auth package is required. Try running "composer require google/auth".');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException('For using the Bedrock platform, the google/auth package is required. Try running "composer require google/auth".');
throw new RuntimeException('For using the Vertex AI platform, google/auth package is required for authentication via application default credentials. Try running "composer require google/auth".');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it already.
Pushing the change in a few moments.

Copy link

@faizanakram99 faizanakram99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, ship it

@junaidbinfarooq
Copy link
Contributor Author

junaidbinfarooq commented Aug 12, 2025

lgtm, ship it

Docs and AI bundle integration need to be added first.

@junaidbinfarooq
Copy link
Contributor Author

@chr-hertel
The PR is ready for review. Please review the changes and let me know your thoughts.
Thanks.

- Adds initial support to integrate text generation using vertex AI
- Adds tests to verify the behavior
- Adds examples to interact with vertex ai
- Adds documentation for vertex ai
@junaidbinfarooq junaidbinfarooq force-pushed the feat/platform-support-for-vertex-ai branch from 1346440 to b08d7e7 Compare August 13, 2025 05:16
* }
* }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indention looks wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PHP doc, the IDE doesn't apparently help with the indentation in this case.
I tried to correct the indentation now.

* file that was distributed with this source code.
*/

use Google\Auth\ApplicationDefaultCredentials;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a new require in the examples/composer.json file - cannot run the examples locally at this point, sorry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a biggie.
I did think about it, but somehow it skipped my mind, probably because the examples worked for me as I included the autoload file in another way.

@@ -52,6 +52,9 @@ Configuration
api_version: '%env(AZURE_GPT_VERSION)%'
gemini:
api_key: '%env(GEMINI_API_KEY)%'
vertexAi:
Copy link
Member

@chr-hertel chr-hertel Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be

Suggested change
vertexAi:
vertex_ai:

Copy link
Contributor Author

@junaidbinfarooq junaidbinfarooq Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it require a change inside AiBundle.php too? While integrating the bridge into the AI bundle, I looked for other bridges that had multiple words in them and found that they were added as a single word. And I followed suit.
I did, however, change it to vertexai.
Given your input on it, however, I'd be happy to change it to vertex_ai.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a similar doc to the gemini one, please combine the two files a la Server Tools - supported by VertexAI and Gemini API or sth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this on purpose so that when we later make a decision about whether we need both the bridges or only Vertex AI, then we could make such a refactor.

@@ -34,7 +34,7 @@ Configuration
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI

**Advanced Example with Anthropic, Azure, Gemini and multiple agents**
**Advanced Example with Anthropic, Azure, Gemini, VertexAi and multiple agents**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the official product name is "Vertex AI" i guess

Suggested change
**Advanced Example with Anthropic, Azure, Gemini, VertexAi and multiple agents**
**Advanced Example with Anthropic, Azure, Gemini, Vertex AI and multiple agents**

@@ -73,13 +73,15 @@ usually defined by the specific models and their documentation.
* `OpenAI's GPT`_ with `OpenAI`_ and `Azure`_ as Platform
* `Anthropic's Claude`_ with `Anthropic`_ and `AWS Bedrock`_ as Platform
* `Meta's Llama`_ with `Azure`_, `Ollama`_, `Replicate`_ and `AWS Bedrock`_ as Platform
* `Gemini`_ with `Google`_ and `OpenRouter`_ as Platform
* `Gemini`_ with `Google`_, `VertexAi`_ and `OpenRouter`_ as Platform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `Gemini`_ with `Google`_, `VertexAi`_ and `OpenRouter`_ as Platform
* `Gemini`_ with `Google`_, `Vertex AI`_ and `OpenRouter`_ as Platform

@chr-hertel
Copy link
Member

Thanks @junaidbinfarooq for your work on this - I think we're getting somewhere.
Please see my comments and review once again yourself with those in mind - not sure I catched everything.

In general it great to have that bridge, I still wonder tho about the amount of duplicated code with the Gemini bridge and we would need to support API Keys as well ... but both topics are fine as follow up

@junaidbinfarooq
Copy link
Contributor Author

junaidbinfarooq commented Aug 13, 2025

Thanks @junaidbinfarooq for your work on this - I think we're getting somewhere. Please see my comments and review once again yourself with those in mind - not sure I catched everything.

In general it great to have that bridge, I still wonder tho about the amount of duplicated code with the Gemini bridge and we would need to support API Keys as well ... but both topics are fine as follow up

@chr-hertel
You're welcome 😄
The duplication is expected as I did not touch the existing Gemini bridge code.
This is what I also pointed out in the PR description about possibly having Vertex AI only as we move forward.
If this is done, there would be no duplication anywhere as far as Google bridges are concerned.
And yes, I do believe this is better done in a follow-up PR after a proper discussion on the topic.

- Adds support to calculate the token usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature Platform Issues & PRs about the AI Platform component Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants